package org.pictual.controller.mainPackage;

import java.util.Vector;

public class DefinitionList {

    private Vector<String> _definitions;
    private Vector<String> _examples;
    private String pronunciation;
    private Vector<String> _audios;
    private String gender;
    private String plural;
    private int count;
    private Boolean verb;
    private Boolean isPlural;

    DefinitionList() {
        _definitions = new Vector<String>();
        _definitions.add("<ol>");
        _examples = new Vector<String>();
        _audios = new Vector<String>();
        gender = "";
        pronunciation = "";
        plural = "";
        count = 1;
        verb = false;
        isPlural = false;
    }



    public void addDefinition(String definition) {
        /*while(definition.indexOf("<a") >= 0){
            String ref = definition.substring(definition.indexOf("<a"), definition.indexOf("</a>")+4);
            //System.out.println("Ex:"+ref);
            String cadena = ref.substring(ref.indexOf(">")+1, ref.indexOf("</a>"));
            //System.out.println("Ex:"+cadena);
            definition = definition.replace(ref, cadena);
        }*/
        while(definition.indexOf("<") >= 0){
            String ref = definition.substring(definition.indexOf("<"), definition.indexOf(">")+1);
            definition = definition.replace(ref, "");
        }
        while(definition.indexOf("[") >= 0){
            String ref = definition.substring(definition.indexOf("["), definition.indexOf("]")+1);
            definition = definition.replace(ref, "");
        }
        if(definition.contains("Plural form of") || definition.contains("plural of") 
                || definition.contains("plural form of") || definition.contains("Plural of")
                || definition.contains("Plural des") || definition.contains("Pluriel d")
                || definition.contains("pluriel d") || definition.contains("Plural de")
                || definition.contains("plural de") || definition.contains("Plural von")){
            isPlural = true;
        }

        _definitions.add("<li><span class=\"number\">"+count+".</span> "+definition);
        count++;
    }

    public String getDefinition(int index) {
        if (_definitions == null) {
            return null;
        }
        return _definitions.elementAt(index);
    }

    public Vector<String> getDefinitions() {
        if (_definitions == null) {
            return null;
        }
        return _definitions;
    }

    public int numDefinitions() {
        if (_definitions == null) {
            return 0;
        }
        return _definitions.size();
    }

    public void addExample(String example) {
        /*while(example.indexOf("<a") >= 0){
            String ref = example.substring(example.indexOf("<a"), example.indexOf("</a>")+4);
            //System.out.println("Ex:"+ref);
            String cadena = ref.substring(ref.indexOf(">")+1, ref.indexOf("</a>"));
            //System.out.println("Ex:"+cadena);
            example = example.replace(ref, cadena);
        }*/
        while(example.indexOf("<") >= 0){
            String ref = example.substring(example.indexOf("<"), example.indexOf(">")+1);
            example = example.replace(ref, "");
        }
        while(example.indexOf("[") >= 0){
            String ref = example.substring(example.indexOf("["), example.indexOf("]")+1);
            example = example.replace(ref, "");
        }
        example = example.replaceAll("\"", "");
        _examples.add(count+example);
    }

    public void addExampleGerman(String example) {
        /*while(example.indexOf("<a") >= 0){
            String ref = example.substring(example.indexOf("<a"), example.indexOf("</a>")+4);
            //System.out.println("Ex:"+ref);
            String cadena = ref.substring(ref.indexOf(">")+1, ref.indexOf("</a>"));
            //System.out.println("Ex:"+cadena);
            example = example.replace(ref, cadena);
        }*/
        while(example.indexOf("<") >= 0){
            String ref = example.substring(example.indexOf("<"), example.indexOf(">")+1);
            example = example.replace(ref, "");
        }
        while(example.indexOf("[") >= 0){
            String ref = example.substring(example.indexOf("["), example.indexOf("]")+1);
            example = example.replace(ref, "");
        }
        _examples.add(example);
    }

    public String getExample(int index) {
        if (_examples == null) {
            return null;
        }
        return _examples.elementAt(index);
    }

    public Vector<String> getExamples() {
        if (_examples == null) {
            return null;
        }
        return _examples;
    }

    public int numExamples() {
        if (_examples == null) {
            return 0;
        }
        return _examples.size();
    }

    public void setPronunciation(String pro){
        for(int i = 0; i < pro.length(); i++){
            char a = pro.charAt(i);
            if(a != '[' && a != ']' && a != '(' && a != ')' && a != '/'){
                pronunciation += a;
            }
        }
    }

    public String getPronunciation(){
        return pronunciation;
    }

    public void setGender(String gen){
        gender = gen;
    }

    public String getGender(){
        return gender;
    }

    public void setPlural(String pl){
        plural = pl;
        if(plural.contains("die")){
            plural = plural.replace("die ", "");
        }
    }

    public String getPlural(){
        return plural;
    }

    public void setVerb(Boolean v){
        verb = v;
    }

    public Boolean getVerb(){
        return verb;
    }

    public void addAudio(String au){
        _audios.add(au);
    }

    public Vector<String> getAudios(){
        return _audios;
    }

    public Boolean isPlural(){
        return isPlural;
    }
}

